home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_1 / easyprocess / source / launch / waitprocs.c < prev    next >
C/C++ Source or Header  |  1992-09-07  |  2KB  |  83 lines

  1. #include <arpbase.h>
  2. #include <arp_proto.h>
  3. #include "Launch.h"
  4. #include "LaunchPriv.h"
  5.  
  6.  
  7. /*
  8.  *    NAME
  9.  *        WaitProcesses -- wait for all child processes to end.
  10.  *
  11.  *    SYNOPSIS
  12.  *        WaitProcesses ()
  13.  *
  14.  *        void WaitProcesses (void);
  15.  *
  16.  *    FUNCTION
  17.  *        Wait until all processes that were launched by this process
  18.  *        are finished.  You MUST call this at the end of your program
  19.  *        since it also cleans up some memory allocation when there are
  20.  *        no more child.
  21.  *
  22.  *    DESCRIPTION
  23.  *        Scan the process pair list and for each process that we are
  24.  *        the parent of we wait until it ends and we remove the process
  25.  *        pair and free the memory.
  26.  *
  27.  *        When all process pair have been scanned, we free the parent's
  28.  *        signal bit and try to free the list.
  29.  *
  30.  *        The fact that we wait while we scan the list does not matter
  31.  *        since the list cannot go away (it contain at least one pair,
  32.  *        ours) and the next pointer is only used AFTER we return from
  33.  *        the wait.
  34.  *
  35.  *    INPUT
  36.  *        None.
  37.  *
  38.  *    OUTPUT
  39.  *        None.
  40.  *
  41.  *    HISTORY
  42.  *        1992/09/06    Pierre Baillargeon        Creation
  43.  *        1992/09/07    Pierre Baillargeon        Update
  44.  *                    Made faster and simpler.
  45.  *
  46.  *    SEE ALSO
  47.  *        WaitProcess(), WaitProcFunc()
  48.  */
  49.  
  50. void WaitProcesses (void)
  51. {
  52.     struct ProcPair *pp, *ppn;
  53.     struct Process *Proc;
  54.     LONG Bit;
  55.  
  56.     Bit = -1L;
  57.     Proc = (struct Process *)FindTask (NULL);
  58.  
  59.     Forbid ();
  60.     for (pp = (struct ProcPair *)ProcPairList->lh_Head; pp->pp_Node.ln_Succ; pp = ppn)
  61.     {
  62.         if (Proc == pp->pp_Parent)
  63.         {
  64.             Bit = pp->pp_ParentBit;
  65.             while (pp->pp_ChildEntry)
  66.             {
  67.                 Wait (1L << Bit | KILL_PROCESS_FLAG);
  68.             }
  69.             ppn = (struct ProcPair *)pp->pp_Node.ln_Succ;
  70.             Remove (&pp->pp_Node);
  71.             FreeMem (pp, sizeof (struct ProcPair));
  72.         }
  73.         else
  74.         {
  75.             ppn = (struct ProcPair *)pp->pp_Node.ln_Succ;
  76.         }
  77.     }
  78.  
  79.     FreeParentSignal (Bit);
  80.     FreeProcPairList ();
  81.     Permit ();
  82. }
  83.